package com.zretc.device.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.zretc.device.dao.AdminDao;
import com.zretc.device.dao.Device_AdminDao;
import com.zretc.device.dao.UserDao;
import com.zretc.device.entity.Admin;
import com.zretc.device.entity.Device_Admin;
import com.zretc.device.entity.User;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.JScrollPane;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JPasswordField;
import javax.swing.DefaultComboBoxModel;

public class MenuFrameAdmin extends JFrame {

	private JPanel contentPane;
	private JTextField txtusername;
	private JTextField txtusercode;
	private JPasswordField txtpassword;
	private JPasswordField txtpassconfirm;
	private JTextField txtName;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MenuFrameAdmin frame = new MenuFrameAdmin();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MenuFrameAdmin() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 851, 530);

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu mnNewMenu_5 = new JMenu("用户管理");
		menuBar.add(mnNewMenu_5);

		JMenuItem mntmNewMenuItem_10 = new JMenuItem("新增用户");
		mntmNewMenuItem_10.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				UserAddDialog uad = new UserAddDialog();
				// 设置为模态属性
				uad.setModal(true);
				// 设置为可见
				uad.setVisible(true);
			}
		});
		mnNewMenu_5.add(mntmNewMenuItem_10);

		JMenu mnNewMenu = new JMenu("库存管理");
		menuBar.add(mnNewMenu);

		JMenuItem mntmNewMenuItem_1 = new JMenuItem("新增设备");
		mntmNewMenuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 创建对象
				DeviceAddDialog dad = new DeviceAddDialog();
				// 设置为模态属性
				dad.setModal(true);
				// 显示该窗口
				dad.setVisible(true);
				// 刷新
			}
		});
		mnNewMenu.add(mntmNewMenuItem_1);

		JMenuItem mntmNewMenuItem_12 = new JMenuItem("查询和修改");
		mntmNewMenuItem_12.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DeviceFindDialog dfd = new DeviceFindDialog();
				// 设为为模态属性
				dfd.setModal(true);
				// 设为可见
				dfd.setVisible(true);
			}
		});
		mnNewMenu.add(mntmNewMenuItem_12);

		JMenu mnNewMenu_1 = new JMenu("入库管理");
		menuBar.add(mnNewMenu_1);

		JMenuItem mntmNewMenuItem_2 = new JMenuItem("新增入库");
		mntmNewMenuItem_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 调转到该对象
				Device_InAddDialog diad = new Device_InAddDialog();
				// 设置为模态窗口
				diad.setModal(true);
				// 显示窗口
				diad.setVisible(true);
			}
		});
		mnNewMenu_1.add(mntmNewMenuItem_2);

		JMenuItem mntmNewMenuItem = new JMenuItem("查询和修改");
		mntmNewMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Device_InFindDialog difd = new Device_InFindDialog();
				// 设置为模态窗口
				difd.setModal(true);
				// 显示
				difd.setVisible(true);
			}
		});
		mnNewMenu_1.add(mntmNewMenuItem);

		JMenu mnNewMenu_2 = new JMenu("出库管理");
		menuBar.add(mnNewMenu_2);

		JMenuItem mntmNewMenuItem_3 = new JMenuItem("新增出库");
		mntmNewMenuItem_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Device_OutAddDialog doad = new Device_OutAddDialog();
				// 设置为模态属性
				doad.setModal(true);
				// 显示窗口
				doad.setVisible(true);
			}
		});
		mnNewMenu_2.add(mntmNewMenuItem_3);

		JMenuItem mntmNewMenuItem_4 = new JMenuItem("查询和修改");
		mntmNewMenuItem_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 跳转
				Device_OutFindDialog doutfind = new Device_OutFindDialog();
				// 设置为模态属性
				doutfind.setModal(true);
				// 显示此窗口
				doutfind.setVisible(true);
			}
		});
		mnNewMenu_2.add(mntmNewMenuItem_4);

		JMenu mnNewMenu_3 = new JMenu("还库管理");
		menuBar.add(mnNewMenu_3);

		JMenuItem mntmNewMenuItem_5 = new JMenuItem("新增还库");
		mntmNewMenuItem_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Device_ReturnAddDialog drad = new Device_ReturnAddDialog();
				// 设置为模态窗
				drad.setModal(true);
				// 显示此窗口
				drad.setVisible(true);
			}
		});
		mnNewMenu_3.add(mntmNewMenuItem_5);

		JMenuItem mntmNewMenuItem_6 = new JMenuItem("查询和修改");
		mntmNewMenuItem_6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 创建跳转的对象
				Device_ReturnFindDialog drfd = new Device_ReturnFindDialog();
				// 设置为模态框
				drfd.setModal(true);
				// 设置为可见
				drfd.setVisible(true);
			}
		});
		mnNewMenu_3.add(mntmNewMenuItem_6);

		JMenu mnNewMenu_4 = new JMenu(" 需求管理");
		menuBar.add(mnNewMenu_4);

		JMenuItem mntmNewMenuItem_7 = new JMenuItem("新增需求");
		mntmNewMenuItem_7.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Device_needAddDialog dad = new Device_needAddDialog();
				// 设置为模态属性
				dad.setModal(true);
				// 显示
				dad.setVisible(true);
			}
		});
		mnNewMenu_4.add(mntmNewMenuItem_7);

		JMenuItem mntmNewMenuItem_8 = new JMenuItem("查询和修改");
		mntmNewMenuItem_8.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 跳转
				Device_needFindDialog dfd = new Device_needFindDialog();
				// 设置为模态属性
				dfd.setModal(true);
				// 显示
				dfd.setVisible(true);
			}
		});
		mnNewMenu_4.add(mntmNewMenuItem_8);
		
		JMenu mnNewMenu_6 = new JMenu("个人中心");
		menuBar.add(mnNewMenu_6);
		
		JMenuItem mntmNewMenuItem_9 = new JMenuItem("退出登录");
		mntmNewMenuItem_9.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//跳转
				UserLoginFrame user =new UserLoginFrame();
				setVisible(false);
				user.setVisible(true);
			}
		});
		mnNewMenu_6.add(mntmNewMenuItem_9);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel label = new JLabel("用户信息管理");
		label.setFont(new Font("宋体", Font.PLAIN, 40));
		label.setBounds(270, 37, 280, 47);
		contentPane.add(label);

		JComboBox txtCB = new JComboBox();
		txtCB.setModel(new DefaultComboBoxModel(new String[] { "普通员工", "仓库员工", "管理员" }));
		txtCB.setFont(new Font("宋体", Font.PLAIN, 20));
		txtCB.setBounds(301, 116, 249, 30);
		contentPane.add(txtCB);

		JLabel label_1 = new JLabel("请选择用户类型");
		label_1.setFont(new Font("宋体", Font.PLAIN, 25));
		label_1.setBounds(105, 110, 181, 38);
		contentPane.add(label_1);

		txtusername = new JTextField();
		txtusername.setFont(new Font("宋体", Font.PLAIN, 25));
		txtusername.setColumns(10);
		txtusername.setBounds(300, 161, 250, 30);
		contentPane.add(txtusername);

		JLabel label_2 = new JLabel("请输入用 户 名");
		label_2.setFont(new Font("宋体", Font.PLAIN, 25));
		label_2.setBounds(105, 161, 181, 30);
		contentPane.add(label_2);

		txtusercode = new JTextField();
		txtusercode.setEditable(false);
		txtusercode.setFont(new Font("宋体", Font.PLAIN, 25));
		txtusercode.setColumns(10);
		txtusercode.setBounds(300, 204, 250, 30);
		contentPane.add(txtusercode);

		JLabel label_3 = new JLabel("用户昵称");
		label_3.setFont(new Font("宋体", Font.PLAIN, 25));
		label_3.setBounds(180, 204, 106, 30);
		contentPane.add(label_3);

		JLabel label_4 = new JLabel("密    码");
		label_4.setFont(new Font("宋体", Font.PLAIN, 25));
		label_4.setBounds(180, 251, 106, 30);
		contentPane.add(label_4);

		txtpassword = new JPasswordField();
		txtpassword.setBounds(300, 251, 250, 30);
		contentPane.add(txtpassword);

		JButton button = new JButton("删除");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String txt = txtCB.getSelectedItem() + "";
				String username = txtusername.getText();
				if (username.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "用户名不能为空");
				} else {
					int n = JOptionPane.showConfirmDialog(null, "请问是否继续删除？删除后将无法恢复！", "删除用户名为: " + username + " 的所有信息",
							JOptionPane.YES_NO_OPTION);
					if (n == 0) {
						if (txt.equals("普通员工")) {
							UserDao ud = new UserDao();
							boolean flag = ud.delUser(username);
							// 对返回值进行判断
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除失败");
							}
						} else if (txt.equals("仓库员工")) {
							Device_AdminDao dad = new Device_AdminDao();
							boolean flag = dad.delDevAdmin(username);
							// 对返回值进行判断
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除失败");
							}
						} else if (txt.equals("管理员")) {
							AdminDao ad = new AdminDao();
							boolean flag = ad.delAdmin(username);
							// 对返回值进行判断
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除失败");
							}
						}
					}
				}

			}
		});
		button.setFont(new Font("宋体", Font.PLAIN, 25));
		button.setBounds(581, 251, 125, 30);
		contentPane.add(button);

		JButton button_1 = new JButton("修改");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 下拉框
				String txt = txtCB.getSelectedItem() + "";
				String username = txtusername.getText();
				String usercode = txtusercode.getText();
				char[] cpassword = txtpassword.getPassword();
				char[] cpassconfirm = txtpassconfirm.getPassword();
				// 转型
				String password = new String(cpassword);
				String passconfirm = new String(cpassconfirm);
				// 判断
				if (username.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "用户名不能为空");
				} else if (usercode.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "用户昵称不能为空");
				} else if (password.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "密码不能为空");
				} else if (passconfirm.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "密码不能为空");
				} else {
					if (password.equals(passconfirm)) {
						if (txt.equals("普通员工")) {
							// 创建对象
							UserDao ud = new UserDao();
							User user = new User(username, null, password);
							boolean flag = ud.modUser(user);
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改失败");
							}
						} else if (txt.equals("仓库员工")) {
							Device_AdminDao dad = new Device_AdminDao();
							Device_Admin device_Admin = new Device_Admin(username, null, password);
							boolean flag = dad.modDevAdmin(device_Admin);
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改失败");
							}
						} else if (txt.equals("管理员")) {
							AdminDao ad = new AdminDao();
							Admin admin = new Admin(username, null, password);
							boolean flag = ad.modAdmin(admin);
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改失败");
							}
						}
					} else {
						// 弹窗提示
						JOptionPane.showMessageDialog(null, "密码错误");
					}
				}
			}
		});
		button_1.setFont(new Font("宋体", Font.PLAIN, 25));
		button_1.setBounds(581, 204, 125, 30);
		contentPane.add(button_1);

		JLabel label_5 = new JLabel("确认密码");
		label_5.setFont(new Font("宋体", Font.PLAIN, 25));
		label_5.setBounds(180, 301, 106, 30);
		contentPane.add(label_5);

		txtpassconfirm = new JPasswordField();
		txtpassconfirm.setBounds(300, 301, 250, 30);
		contentPane.add(txtpassconfirm);

		JButton button_2 = new JButton("查询");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String txt = txtCB.getSelectedItem() + "";
				String username = txtusername.getText();
				// 调用查询的方法
				if (username.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "用户名不能为空");
				} else {
					if (txt.equals("普通员工")) {
						// 创建对象
						UserDao ud = new UserDao();
						User user = ud.findUserById(username);
						if (user == null) {
							// 弹窗提示
							JOptionPane.showMessageDialog(null, "该员工不存在");
						} else {
							txtusercode.setText(user.getUsercode());
						}

					} else if (txt.equals("仓库员工")) {
						Device_AdminDao dad = new Device_AdminDao();
						Device_Admin da = dad.findDevAdminById(username);
						if (da == null) {
							// 弹窗提示
							JOptionPane.showMessageDialog(null, "该员工不存在");
						} else {
							txtusercode.setText(da.getUsercode());
						}

					} else if (txt.equals("管理员")) {
						AdminDao ad = new AdminDao();
						Admin admin = ad.findAdminById(username);
						if (admin == null) {
							// 弹窗提示
							JOptionPane.showMessageDialog(null, "该员工不存在");
						} else {
							txtusercode.setText(admin.getUsercode());
						}

					}
				}
			}
		});
		button_2.setFont(new Font("宋体", Font.PLAIN, 25));
		button_2.setBounds(581, 161, 125, 30);
		contentPane.add(button_2);

		JButton button_3 = new JButton("清空");
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtusername.setText("");
				txtusercode.setText("");
				txtpassword.setText("");
				txtpassconfirm.setText("");
			}
		});
		button_3.setFont(new Font("宋体", Font.PLAIN, 25));
		button_3.setBounds(581, 301, 125, 30);
		contentPane.add(button_3);
		
		JLabel label_6 = new JLabel("欢迎您：");
		label_6.setFont(new Font("宋体", Font.PLAIN, 20));
		label_6.setBounds(561, 37, 80, 30);
		contentPane.add(label_6);
		
		txtName = new JTextField();
		txtName.setFont(new Font("宋体", Font.PLAIN, 17));
		txtName.setColumns(10);
		txtName.setBounds(633, 37, 73, 25);
		contentPane.add(txtName);
		// 居中
		setLocationRelativeTo(null);
	}
	
	/**
	 * 带参构造
	 */
	public MenuFrameAdmin(String userName) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 851, 530);

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu mnNewMenu_5 = new JMenu("用户管理");
		menuBar.add(mnNewMenu_5);

		JMenuItem mntmNewMenuItem_10 = new JMenuItem("新增用户");
		mntmNewMenuItem_10.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				UserAddDialog uad = new UserAddDialog();
				// 设置为模态属性
				uad.setModal(true);
				// 设置为可见
				uad.setVisible(true);
			}
		});
		mnNewMenu_5.add(mntmNewMenuItem_10);

		JMenu mnNewMenu = new JMenu("库存管理");
		menuBar.add(mnNewMenu);

		JMenuItem mntmNewMenuItem_1 = new JMenuItem("新增设备");
		mntmNewMenuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 创建对象
				DeviceAddDialog dad = new DeviceAddDialog();
				// 设置为模态属性
				dad.setModal(true);
				// 显示该窗口
				dad.setVisible(true);
				// 刷新
			}
		});
		mnNewMenu.add(mntmNewMenuItem_1);

		JMenuItem mntmNewMenuItem_12 = new JMenuItem("查询和修改");
		mntmNewMenuItem_12.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DeviceFindDialog dfd = new DeviceFindDialog();
				// 设为为模态属性
				dfd.setModal(true);
				// 设为可见
				dfd.setVisible(true);
			}
		});
		mnNewMenu.add(mntmNewMenuItem_12);

		JMenu mnNewMenu_1 = new JMenu("入库管理");
		menuBar.add(mnNewMenu_1);

		JMenuItem mntmNewMenuItem_2 = new JMenuItem("新增入库");
		mntmNewMenuItem_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 调转到该对象
				Device_InAddDialog diad = new Device_InAddDialog();
				// 设置为模态窗口
				diad.setModal(true);
				// 显示窗口
				diad.setVisible(true);
			}
		});
		mnNewMenu_1.add(mntmNewMenuItem_2);

		JMenuItem mntmNewMenuItem = new JMenuItem("查询和修改");
		mntmNewMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Device_InFindDialog difd = new Device_InFindDialog();
				// 设置为模态窗口
				difd.setModal(true);
				// 显示
				difd.setVisible(true);
			}
		});
		mnNewMenu_1.add(mntmNewMenuItem);

		JMenu mnNewMenu_2 = new JMenu("出库管理");
		menuBar.add(mnNewMenu_2);

		JMenuItem mntmNewMenuItem_3 = new JMenuItem("新增出库");
		mntmNewMenuItem_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Device_OutAddDialog doad = new Device_OutAddDialog();
				// 设置为模态属性
				doad.setModal(true);
				// 显示窗口
				doad.setVisible(true);
			}
		});
		mnNewMenu_2.add(mntmNewMenuItem_3);

		JMenuItem mntmNewMenuItem_4 = new JMenuItem("查询和修改");
		mntmNewMenuItem_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 跳转
				Device_OutFindDialog doutfind = new Device_OutFindDialog();
				// 设置为模态属性
				doutfind.setModal(true);
				// 显示此窗口
				doutfind.setVisible(true);
			}
		});
		mnNewMenu_2.add(mntmNewMenuItem_4);

		JMenu mnNewMenu_3 = new JMenu("还库管理");
		menuBar.add(mnNewMenu_3);

		JMenuItem mntmNewMenuItem_5 = new JMenuItem("新增还库");
		mntmNewMenuItem_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Device_ReturnAddDialog drad = new Device_ReturnAddDialog();
				// 设置为模态窗
				drad.setModal(true);
				// 显示此窗口
				drad.setVisible(true);
			}
		});
		mnNewMenu_3.add(mntmNewMenuItem_5);

		JMenuItem mntmNewMenuItem_6 = new JMenuItem("查询和修改");
		mntmNewMenuItem_6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 创建跳转的对象
				Device_ReturnFindDialog drfd = new Device_ReturnFindDialog();
				// 设置为模态框
				drfd.setModal(true);
				// 设置为可见
				drfd.setVisible(true);
			}
		});
		mnNewMenu_3.add(mntmNewMenuItem_6);

		JMenu mnNewMenu_4 = new JMenu(" 需求管理");
		menuBar.add(mnNewMenu_4);

		JMenuItem mntmNewMenuItem_7 = new JMenuItem("新增需求");
		mntmNewMenuItem_7.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Device_needAddDialog dad = new Device_needAddDialog();
				// 设置为模态属性
				dad.setModal(true);
				// 显示
				dad.setVisible(true);
			}
		});
		mnNewMenu_4.add(mntmNewMenuItem_7);

		JMenuItem mntmNewMenuItem_8 = new JMenuItem("查询和修改");
		mntmNewMenuItem_8.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 跳转
				Device_needFindDialog dfd = new Device_needFindDialog();
				// 设置为模态属性
				dfd.setModal(true);
				// 显示
				dfd.setVisible(true);
			}
		});
		mnNewMenu_4.add(mntmNewMenuItem_8);
		
		JMenu mnNewMenu_6 = new JMenu("个人中心");
		menuBar.add(mnNewMenu_6);
		
		JMenuItem mntmNewMenuItem_9 = new JMenuItem("退出登录");
		mntmNewMenuItem_9.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//跳转
				UserLoginFrame user =new UserLoginFrame();
				setVisible(false);
				user.setVisible(true);
			}
		});
		mnNewMenu_6.add(mntmNewMenuItem_9);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel label = new JLabel("用户信息管理");
		label.setFont(new Font("宋体", Font.PLAIN, 40));
		label.setBounds(270, 37, 280, 47);
		contentPane.add(label);

		JComboBox txtCB = new JComboBox();
		txtCB.setModel(new DefaultComboBoxModel(new String[] { "普通员工", "仓库员工", "管理员" }));
		txtCB.setFont(new Font("宋体", Font.PLAIN, 20));
		txtCB.setBounds(301, 116, 249, 30);
		contentPane.add(txtCB);

		JLabel label_1 = new JLabel("请选择用户类型");
		label_1.setFont(new Font("宋体", Font.PLAIN, 25));
		label_1.setBounds(105, 110, 181, 38);
		contentPane.add(label_1);

		txtusername = new JTextField();
		txtusername.setFont(new Font("宋体", Font.PLAIN, 25));
		txtusername.setColumns(10);
		txtusername.setBounds(300, 161, 250, 30);
		contentPane.add(txtusername);

		JLabel label_2 = new JLabel("请输入用 户 名");
		label_2.setFont(new Font("宋体", Font.PLAIN, 25));
		label_2.setBounds(105, 161, 181, 30);
		contentPane.add(label_2);

		txtusercode = new JTextField();
		txtusercode.setEditable(false);
		txtusercode.setFont(new Font("宋体", Font.PLAIN, 25));
		txtusercode.setColumns(10);
		txtusercode.setBounds(300, 204, 250, 30);
		contentPane.add(txtusercode);

		JLabel label_3 = new JLabel("用户昵称");
		label_3.setFont(new Font("宋体", Font.PLAIN, 25));
		label_3.setBounds(180, 204, 106, 30);
		contentPane.add(label_3);

		JLabel label_4 = new JLabel("密    码");
		label_4.setFont(new Font("宋体", Font.PLAIN, 25));
		label_4.setBounds(180, 251, 106, 30);
		contentPane.add(label_4);

		txtpassword = new JPasswordField();
		txtpassword.setBounds(300, 251, 250, 30);
		contentPane.add(txtpassword);

		JButton button = new JButton("删除");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String txt = txtCB.getSelectedItem() + "";
				String username = txtusername.getText();
				if (username.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "用户名不能为空");
				} else {
					int n = JOptionPane.showConfirmDialog(null, "请问是否继续删除？删除后将无法恢复！", "删除用户名为: " + username + " 的所有信息",
							JOptionPane.YES_NO_OPTION);
					if (n == 0) {
						if (txt.equals("普通员工")) {
							UserDao ud = new UserDao();
							boolean flag = ud.delUser(username);
							// 对返回值进行判断
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除失败");
							}
						} else if (txt.equals("仓库员工")) {
							Device_AdminDao dad = new Device_AdminDao();
							boolean flag = dad.delDevAdmin(username);
							// 对返回值进行判断
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除失败");
							}
						} else if (txt.equals("管理员")) {
							AdminDao ad = new AdminDao();
							boolean flag = ad.delAdmin(username);
							// 对返回值进行判断
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "删除失败");
							}
						}
					}
				}

			}
		});
		button.setFont(new Font("宋体", Font.PLAIN, 25));
		button.setBounds(581, 251, 125, 30);
		contentPane.add(button);

		JButton button_1 = new JButton("修改");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 下拉框
				String txt = txtCB.getSelectedItem() + "";
				String username = txtusername.getText();
				String usercode = txtusercode.getText();
				char[] cpassword = txtpassword.getPassword();
				char[] cpassconfirm = txtpassconfirm.getPassword();
				// 转型
				String password = new String(cpassword);
				String passconfirm = new String(cpassconfirm);
				// 判断
				if (username.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "用户名不能为空");
				} else if (usercode.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "用户昵称不能为空");
				} else if (password.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "密码不能为空");
				} else if (passconfirm.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "密码不能为空");
				} else {
					if (password.equals(passconfirm)) {
						if (txt.equals("普通员工")) {
							// 创建对象
							UserDao ud = new UserDao();
							User user = new User(username, null, password);
							boolean flag = ud.modUser(user);
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改失败");
							}
						} else if (txt.equals("仓库员工")) {
							Device_AdminDao dad = new Device_AdminDao();
							Device_Admin device_Admin = new Device_Admin(username, null, password);
							boolean flag = dad.modDevAdmin(device_Admin);
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改失败");
							}
						} else if (txt.equals("管理员")) {
							AdminDao ad = new AdminDao();
							Admin admin = new Admin(username, null, password);
							boolean flag = ad.modAdmin(admin);
							if (flag) {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改成功");
							} else {
								// 弹窗提示
								JOptionPane.showMessageDialog(null, "修改失败");
							}
						}
					} else {
						// 弹窗提示
						JOptionPane.showMessageDialog(null, "密码错误");
					}
				}
			}
		});
		button_1.setFont(new Font("宋体", Font.PLAIN, 25));
		button_1.setBounds(581, 204, 125, 30);
		contentPane.add(button_1);

		JLabel label_5 = new JLabel("确认密码");
		label_5.setFont(new Font("宋体", Font.PLAIN, 25));
		label_5.setBounds(180, 301, 106, 30);
		contentPane.add(label_5);

		txtpassconfirm = new JPasswordField();
		txtpassconfirm.setBounds(300, 301, 250, 30);
		contentPane.add(txtpassconfirm);

		JButton button_2 = new JButton("查询");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String txt = txtCB.getSelectedItem() + "";
				String username = txtusername.getText();
				// 调用查询的方法
				if (username.equals("")) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "用户名不能为空");
				} else {
					if (txt.equals("普通员工")) {
						// 创建对象
						UserDao ud = new UserDao();
						User user = ud.findUserById(username);
						if (user == null) {
							// 弹窗提示
							JOptionPane.showMessageDialog(null, "该员工不存在");
						} else {
							txtusercode.setText(user.getUsercode());
						}

					} else if (txt.equals("仓库员工")) {
						Device_AdminDao dad = new Device_AdminDao();
						Device_Admin da = dad.findDevAdminById(username);
						if (da == null) {
							// 弹窗提示
							JOptionPane.showMessageDialog(null, "该员工不存在");
						} else {
							txtusercode.setText(da.getUsercode());
						}

					} else if (txt.equals("管理员")) {
						AdminDao ad = new AdminDao();
						Admin admin = ad.findAdminById(username);
						if (admin == null) {
							// 弹窗提示
							JOptionPane.showMessageDialog(null, "该员工不存在");
						} else {
							txtusercode.setText(admin.getUsercode());
						}

					}
				}
			}
		});
		button_2.setFont(new Font("宋体", Font.PLAIN, 25));
		button_2.setBounds(581, 161, 125, 30);
		contentPane.add(button_2);

		JButton button_3 = new JButton("清空");
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtusername.setText("");
				txtusercode.setText("");
				txtpassword.setText("");
				txtpassconfirm.setText("");
			}
		});
		button_3.setFont(new Font("宋体", Font.PLAIN, 25));
		button_3.setBounds(581, 301, 125, 30);
		contentPane.add(button_3);
		
		JLabel label_6 = new JLabel("欢迎您：");
		label_6.setFont(new Font("宋体", Font.PLAIN, 20));
		label_6.setBounds(561, 37, 80, 30);
		contentPane.add(label_6);
		
		txtName = new JTextField();
		//设置为不可编辑
		txtName.setEditable(false);
		AdminDao admin = new AdminDao();
		//调用查找方法
		Admin a=admin.findAdminById(userName);
		txtName.setText(a.getUsercode());
		txtName.setFont(new Font("宋体", Font.PLAIN, 17));
		txtName.setColumns(10);
		txtName.setBounds(633, 37, 73, 25);
		contentPane.add(txtName);
		// 居中
		setLocationRelativeTo(null);
	}
}
